package com.palmind.parser.tags;

public abstract class AbstractTag {
	// //////////////// All tags' type /////////////////////
	public static final int UNKNOW_TAG = -1;
	public static final int NODE_TAG = 0;
	public static final int FONT_TAG = 1;
	public static final int ICON_TAG = 2;
	public static final int ATTRIBUTE_TAG = 3;
	public static final int ATTRIBUTE_LAYOUT_TAG = 4;
	public static final int HOOK_TAG = 5;
	public static final int ARROW_LINK_TAG = 6;
	public static final int RICH_CONTENT_TAG = 7;
	public static final int CLOUD_TAG = 8;
	public static final int MAP_TAG = 9;
	// /////////////////////////////////////////////////////

	/**
	 * All tags' name
	 */
	public static final String[] TAGS = { "node", "font", "icon", "attribute",
			"attribute_layout", "hook", "arrowlink", "richcontent", "cloud",
			"map" };

	protected String[] attributeValues = null;

	/**
	 * Tag's type
	 */
	protected int type = UNKNOW_TAG;

	public static final int getTagType(String tagName) {
		if (tagName == null || tagName.length() == 0)
			return UNKNOW_TAG;
		for (int i = 0; i < TAGS.length; i++)
			if (tagName.equals(TAGS[i]))
				return i;
		return UNKNOW_TAG;
	}

	public static String getTagName(int tagType) {
		if (tagType < NODE_TAG || tagType > MAP_TAG)
			return null;
		else
			return TAGS[tagType];
	}

	public abstract String[] getAttributeNames();

	public int getType() {
		return type;
	}

	public String[] getAttributeValues() {
		return attributeValues;
	}

	public String getAttributeValue(String attributeName) {
		if (attributeName == null)
			return attributeName;
		for (int i = 0; i < getAttributeNames().length; i++)
			if (attributeName.equals(getAttributeNames()[i]))
				return attributeValues[i];
		return null;
	}

	public void setAttributeValue(String attributeName, String attributeValue) {
		if (attributeName == null || attributeValue == null)
			return;
		int attr_num = getAttributeNames() == null ? 0
				: getAttributeNames().length;
		for (int i = 0; i < attr_num; i++)
			if (attributeValues[i] == null
					&& attributeName.equals(getAttributeNames()[i]))
				attributeValues[i] = attributeValue;
	}

}
